package com.zjyd.douyangsystem.controller;

import cn.hutool.core.bean.BeanUtil;
import com.zjyd.douyangcommoncore.entity.DyNews;
import com.zjyd.douyangcommoncore.result.Result;
import com.zjyd.douyangcommoncore.service.DyNewsService;
import com.zjyd.douyangcommoncore.vo.DyNewsVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 新闻相关接口
 */
@Slf4j
@RestController
@Tag(name = "新闻相关")
@RequestMapping("/douyang/system/news")
public class NewsController {

    @Autowired
    private DyNewsService dyNewsService;

    /**
     * 添加新闻
     */
    @Operation(summary = "添加新闻")
    @PostMapping("/add")
    public Result addNews(@RequestBody DyNewsVO dyNewsVO){
        DyNews dyNews = new DyNews();
        BeanUtil.copyProperties(dyNewsVO,dyNews);
        dyNewsService.save(dyNews);
        //给搜索引擎es添加一条对应的文档

        return Result.success();
    }
}
